package GUI;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JTextField;
import javax.swing.JButton;

import Client.BusinessImplements;
import Controler.Delete_Copy_controler;
import Controler.Delete_Item_Controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.border.LineBorder;
/**
  * @author Lucie
 * Class name Delete_item_Panel
 * extend  Abstract_Jpanel
 * purpose: this panel get item id from the user and call the controller 
 * to delete this  item
 */
public class Delete_item_Panel extends Abstract_Jpanel  {
	private JTextField textField;

	/**
	 * Create the panel.
	 */
	public Delete_item_Panel() {
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(32, 46, 559, 256);
		add(panel);
		panel.setLayout(null);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(SystemColor.control, 6));
		panel_1.setBackground(new Color(220, 220, 220));
		panel_1.setBounds(64, 47, 424, 134);
		panel.add(panel_1);
		panel_1.setLayout(null);
		
		textField = new JTextField();
		textField.setBounds(133, 45, 193, 20);
		panel_1.add(textField);
		textField.setColumns(10);
		
		JLabel lblItemId = new JLabel("Item id:");
		lblItemId.setBounds(63, 42, 47, 23);
		panel_1.add(lblItemId);
		lblItemId.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblChooseTheItem = new JLabel("choose the item you like to delete");
		lblChooseTheItem.setForeground(Color.RED);
		lblChooseTheItem.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		lblChooseTheItem.setBounds(63, 76, 322, 29);
		panel_1.add(lblChooseTheItem);
		
		JLabel lblDeleteItem = new JLabel("Delete Item");
		lblDeleteItem.setForeground(new Color(25, 25, 112));
		lblDeleteItem.setFont(new Font("MV Boli", Font.BOLD, 30));
		lblDeleteItem.setBounds(50, 11, 322, 32);
		add(lblDeleteItem);
		
		JButton btnBack = new JButton("back");
		
		/*
		 *  btnBack ;When you click this button you will return to 
		 *  Sign_in_panel screen
		 */
				
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();
			
			}
		});
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnBack.setBounds(61, 313, 97, 35);
		add(btnBack);
		/*
		 *btnDelete=When you click this button you will call delete_Item(textField.getText()))
		 * a method of the controller of this panel if this method return true we will
		 * call the methods of this class next_screen_success(),empty_text_fields();
		 * else we call next_screen_faild(deleteItem_controler.get_msg());	
		 * 	deleteItem_controler.get_msg(); return the msg from the controller with all
		 * the error msg.
		 */
		JButton btnDelete = new JButton("delete");
		btnDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
		 		
					Delete_Item_Controler deleteItem_controler=new Delete_Item_Controler();
					
								if(!deleteItem_controler.delete_Item(textField.getText()))
								{
									 next_screen_faild(deleteItem_controler.get_msg());	
								}
								else
								{
									empty_text_fields();
							 		next_screen_success(); 
								}
				
				
				
			}
		});
		btnDelete.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnDelete.setBounds(480, 313, 97, 39);
		add(btnDelete);

	}

	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * this method display showMessageDialog with a success msg
	 */
	public void next_screen_success()
	{
		JOptionPane.showMessageDialog(this,"apply success");
	}
	/**
	 *this method display showMessageDialog with a failed msg
	 * @param msg
	 */
	public void next_screen_faild(String msg)
	{
		JOptionPane.showMessageDialog(this,"apply faild "+msg);
	}
	/**
	 *  this  set all text fields to be empty
	 */
	public void empty_text_fields()
	{
		textField.setText(null);
	}

}
